import java.util.ArrayList;
import java.util.List;

public class Node {
	List<Edge> my_in;
	List<Edge> my_out;
	double my_demand;
	double throughput;
	Node s;
	Node t;
	String my_name;
	double received;
	// 0 for receive 1 for transmit
	boolean isTransmiting;
  boolean discovered = false;
  boolean explored = false;

	public Node(double demand, String name) {
		my_in = new ArrayList<>();
		my_out = new ArrayList<>();
		my_demand = demand;
		my_name = name;
	}

  public Node() {
  }
	
  public void reset() {
    discovered = false;
  }
  
  public boolean hasOut() {
    for (Edge e : my_out) {
      if (e.my_capacity - e.my_flow >= 0) {
        return true;
      }
    }
    return false;
  }
  
  public Edge nextOut() {
    for (Edge e : my_out) {
      if (e.my_capacity - e.my_flow >= 0) {
        return e;
      }
    }
    return null;
  }
	
	public double incomingValue() {
		double value = 0;
		for (Edge e : my_in) {
			value = value + e.my_capacity;
		}
		return value;
	}

	public void receive(Edge channel) {
		if (!this.isTransmiting & channel.my_v.my_name.equals(this.my_name)
				& this.throughput< this.my_demand) {
			this.throughput = Math.min(this.throughput + channel.my_flow,this.my_demand);
		} else if (this.throughput == this.my_demand & channel.my_v.my_name.equals(this.my_name)) {
			this.received = received + channel.my_flow;
			this.isTransmiting = true;
		}
		this.my_in.remove(channel);
	}

}
